package com.coded2.mobileposto.model;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQuery;

import org.codehaus.jackson.annotate.JsonIgnore;


/**
 * The persistent class for the servico database table.
 * 
 */
@Entity
@NamedQuery(name="Servico.findAll", query="SELECT s FROM Servico s")
public class Servico extends com.coded2.infra.comum.ComumDTO  {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="id_servico")
	private int idServico;

	@Column(name="no_servico")
	private String noServico;

	//bi-directional many-to-many association to Posto
	@JsonIgnore
	@ManyToMany
	@JoinTable(
		name="servico_posto"
		, joinColumns={
			@JoinColumn(name="id_servico")
			}
		, inverseJoinColumns={
			@JoinColumn(name="id_posto")
			}
		)
	private List<Posto> postos;

	public Servico() {
	}

	public int getIdServico() {
		return this.idServico;
	}

	public void setIdServico(int idServico) {
		this.idServico = idServico;
	}

	public String getNoServico() {
		return this.noServico;
	}

	public void setNoServico(String noServico) {
		this.noServico = noServico;
	}

	public List<Posto> getPostos() {
		return this.postos;
	}

	public void setPostos(List<Posto> postos) {
		this.postos = postos;
	}

	@Override
	@JsonIgnore
	public Object getId() {
		return getIdServico();
	}

	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + idServico;
		return result;
	}

	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Servico other = (Servico) obj;
		if (idServico != other.idServico)
			return false;
		return true;
	}

}